/**
 * request请求封装
 * 区分get和post方式
 * @url String:请求地址
 * @data Object: 接口需要传递的参数对象       
 */

// 页面调用例子
// import config from './host' // http://120.0.0.1
// import http from './utils/http'
// const { code, data } = http.get('/api/sendCode') // get请求不带参数
// | const { code, data } = http.get('/api/sendCode', { page:1 }) // get 带参数
//  | const { code, data } = http.post('/api/sendCode', { page:1 }) // post 带参数，不带参数的情况，第二个实参不用传递
 
 const request = (method = '', url ='', data = {}) => {
	 return new Promise((resolve, reject) => {
		 uni.request({
		 	url: config.baseUrl+url,
			method,
			header: {
				'Content-Type': 'application/json; charset=UTF-8',
				'Authorization': uni.getStorageSync('token')   
			},
			data,
			success: res => {
			   resolve(res.data)
			},
			fail: err => {
				reject(err)
			}
		 })
	 })
 }

const get = (url, data) => request('GET', url, data)
const post = (url, data) => request('POST', url, data)
 const http = {
	 get,
	 post
 }
 export default http
 